/**
 * Mockcat Server
 * @author Wangtd
 */
var http = require('http');
var url = require('url');
var fs = require('fs');
var path = require('path');
var express = require('express');
var bodyParser = require('body-parser');

var config = require('./config.js');
var mocker = require('./lib/mocker.js');
var router = require('./lib/router.js');

var app = express();

app.use('/app', express.static(path.join(__dirname, 'app')));
app.use(bodyParser.json({ type: 'application/json', limit: '5mb' }));
app.use('/mock', router);
app.use('/', mocker.listen(config.mockDir));

http.createServer(app).listen(config.port, function(error) {
    if (error) {
        console.error(error);
    } else {
        console.log('Mockcat server is runing at http://127.0.0.1:%d/', config.port);
    }
});
